package com.cskaoyan.service;

import com.cskaoyan.bean.PO.MarketCategory;
import com.cskaoyan.bean.PO.MarketCategoryExample;
import com.cskaoyan.bean.PO.WxCatalogIndexpo;
import com.cskaoyan.bean.VO.WxCatalogIndexVo;
import com.cskaoyan.mapper.MarketCategoryMapper;
import com.cskaoyan.mapper.WxCatalogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @author:刘杰
 * @create: 2022-08-17 09:18
 */
@Service
public class WxcatalogServiceImpl implements WxCatalogService{

    @Autowired
    WxCatalogMapper wxCatalogMapper;

    @Autowired
    MarketCategoryMapper marketCategoryMapper;

    @Override
    public WxCatalogIndexVo index() {
        MarketCategory[] marketCategories = wxCatalogMapper.selectByExample(null);
        WxCatalogIndexVo wxCatalogIndexVo = new WxCatalogIndexVo();
        wxCatalogIndexVo.setCurrentCategory( marketCategories[0]);
        Integer id = marketCategories[0].getId();
        wxCatalogIndexVo.setCategoryList(marketCategories);
        MarketCategoryExample example = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria = example.createCriteria();
        criteria.andIdNotEqualTo(id);
        MarketCategory[] marketCategories1 = wxCatalogMapper.selectByExample(example);
        wxCatalogIndexVo.setCurrentSubCategory(marketCategories1);
        return wxCatalogIndexVo;
    }

    @Override
    public WxCatalogIndexpo current(Integer id) {
        //获取currentCategory
        MarketCategory marketCategory = marketCategoryMapper.selectByPrimaryKey(id);
        //获取currentSubCategory
        MarketCategoryExample marketCategoryExample2 = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria2 = marketCategoryExample2.createCriteria();
        criteria2.andPidEqualTo(id).andDeletedEqualTo(false);
        List<MarketCategory> marketCategories2 = marketCategoryMapper.selectByExample(marketCategoryExample2);

        return new WxCatalogIndexpo(null, marketCategory, marketCategories2);

    }


}
